//
//  RVNavigationController.m
//  RememberVocabularies
//
//  Created by 伍银荣 on 2017/10/11.
//  Copyright © 2017年 WYR. All rights reserved.
//

#import "RVNavigationController.h"

@interface RVNavigationController ()<UIGestureRecognizerDelegate>

@end

@implementation RVNavigationController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    //自定义导航栏返回失效问题
    self.interactivePopGestureRecognizer.delegate = self;
}

+(void)initialize
{
    //根据使用当前nav类自定义navBar
    UINavigationBar *navBar = [UINavigationBar appearanceWhenContainedInInstancesOfClasses:@[[RVNavigationController class]]];
    
    //设置背景
    navBar.barTintColor = MRGlobalBg;
    
    //设置导航条字体
    NSDictionary *dict = @{NSForegroundColorAttributeName:[UIColor whiteColor],NSFontAttributeName:[UIFont systemFontOfSize:16]};
    [navBar setTitleTextAttributes:dict];
    
    //设置导航条上除了标题以外的其他按钮的颜色
    [navBar setTintColor:[UIColor whiteColor]];
}

//拦截push，重写父类（navigationController）的方法
-(void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated
{
    //判断push进来的界面是不是第一个
    if (self.childViewControllers.count > 0) {
        viewController.hidesBottomBarWhenPushed = YES;
      
        viewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"checkUserType_backward_9x15_"] style:UIBarButtonItemStylePlain target:self action:@selector(leftBtnClick)];
        
    }
    //重写父类的方法
    [super pushViewController:viewController animated:YES];
}

//实现左边按钮的点击事件
-(void)leftBtnClick
{
    [self popViewControllerAnimated:YES];
}


-(BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer
{
    return self.childViewControllers.count > 1;
}


//显示状态栏的样式
-(UIStatusBarStyle)preferredStatusBarStyle
{
    return UIStatusBarStyleLightContent;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
